package com.example.bookkeepingelf.business.enums;

import com.example.bookkeepingelf.R;

import java.util.ArrayList;
import java.util.List;

public enum JsqOperatorToResourceIdEnum {

    OPERATOR_ADD(R.id.jsq_operate_add, "＋"),
    OPERATOR_SUB(R.id.jsq_operate_subtract, "－"),
    OPERATOR_MUL(R.id.jsq_operate_multiply, "×"),
    OPERATOR_DIV(R.id.jsq_operate_division, "÷"),
    OPERATOR_EQ(R.id.jsq_operate_back, "＝"),
    OPERATOR_BACK(R.id.jsq_operate_back, "back"),

    ;

    private int id;
    private String operator;

    JsqOperatorToResourceIdEnum(int id, String operator) {
        this.id = id;
        this.operator = operator;
    }

    public int getId() {
        return id;
    }

    public String getOperator() {
        return operator;
    }

    public static JsqOperatorToResourceIdEnum getJsqOperatorToResourceIdEnumById(int id) {
        for (JsqOperatorToResourceIdEnum jsqOperatorToResourceIdEnum : JsqOperatorToResourceIdEnum.values()) {
            if (jsqOperatorToResourceIdEnum.getId() == id) {
                return jsqOperatorToResourceIdEnum;
            }
        }
        return null;
    }

    public static JsqOperatorToResourceIdEnum getJsqOperatorToResourceIdEnumByOperator(String operator){
        for (JsqOperatorToResourceIdEnum jsqOperatorToResourceIdEnum : JsqOperatorToResourceIdEnum.values()) {
            if (jsqOperatorToResourceIdEnum.getOperator().equals(operator)) {
                return jsqOperatorToResourceIdEnum;
            }
        }
        return null;
    }

    /**
     * 获取数学符号
     * @return
     */
    public static List<String> getMathsOperatorList() {
        List<String> operatorList = new ArrayList<>();
        for (JsqOperatorToResourceIdEnum jsqOperatorToResourceIdEnum : JsqOperatorToResourceIdEnum.values()) {
            if (!jsqOperatorToResourceIdEnum.equals(OPERATOR_BACK)) {
                operatorList.add(jsqOperatorToResourceIdEnum.getOperator());
            }
        }
        return operatorList;
    }

    public static List<Integer> getMathsOperatorResourceIdList() {
        List<Integer> list = new ArrayList<>();
        for (JsqOperatorToResourceIdEnum value : JsqOperatorToResourceIdEnum.values()) {
            if (!value.equals(OPERATOR_BACK)) {
                list.add(value.getId());
            }
        }
        return list;
    }
}
